/**
 * 系统UI相关的全局响应式数据
 */
import Vue from 'vue'
import Vuex from 'vuex'
import { getData, setData } from 'app/global'
import { GLOBAL_KEY_CLIENT_TYPE } from 'constants/'
import schoolMenus from '@/menus/school'
import companyMenus from '@/menus/company'
import studentMenus from '@/menus/student'

Vue.use(Vuex)

const userInfo = null

const permissions = []

const unreadNoticeCount = 0

const clientType = getData(GLOBAL_KEY_CLIENT_TYPE) || 'company'

const approval = null

export default new Vuex.Store({
  state: {
    userInfo,
    permissions,
    unreadNoticeCount,
    clientType,
    approval
  },
  mutations: {
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo
    },
    setMenus(state, menus) {
      state.menus = menus
    },
    setPermissions(state, permissions) {
      state.permissions = permissions
    },
    setUnreadNoticeCount(state, unreadNoticeCount) {
      state.unreadNoticeCount = unreadNoticeCount
    },
    setClientType(state, clientType) {
      state.clientType = clientType
      setData(GLOBAL_KEY_CLIENT_TYPE, clientType)
    },
    setApproval(state, approval) {
      state.approval = approval
    }
  },
  getters: {
    menus: state => {
      const { clientType } = state
      if (clientType === 'school') {
        return schoolMenus
      } else if (clientType === 'company') {
        return companyMenus
      } else {
        return studentMenus
      }
    }
  },
  actions: {},
  modules: {}
})
